<?php
class ModelHkWechatInland extends Model {
<<<<<<< HEAD
<<<<<<< HEAD
	public function addWechatInland($data) {
		$this->event->trigger('pre.admin.WechatInland.add', $data);
=======
	public function addVendorChecklist($data) {
		$this->event->trigger('pre.admin.vendor_details.add', $data);
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
=======
	public function addVendorChecklist($data) {
		$this->event->trigger('pre.admin.vendor_details.add', $data);
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa

		if(isset($data['no_1_child'])){
			$no_1_childs = implode(",",$data['no_1_child']);
		}
<<<<<<< HEAD
<<<<<<< HEAD
		if(isset($data['no_2_child'])){
			$no_2_childs = implode(",",$data['no_2_child']);
		}
		if(isset($data['no_3_child'])){
			$no_3_childs = implode(",",$data['no_3_child']);
		}
		if(isset($data['no_4_child'])){
			$no_4_childs = implode(",",$data['no_4_child']);
		}

		// var_dump($no_1_childs);exit;

		$this->db->query("INSERT INTO " . DB_PREFIX . "company_wechat_inland SET customer_name = '" . $this->db->escape($data['customer_name']) . "', admin_name = '" . $this->db->escape($data['admin_name']) . "', admin_email = '" . $this->db->escape($data['admin_email']) . "', admin_tel = '" . $this->db->escape($data['admin_tel']) . "', company_tel = '" . $this->db->escape($data['company_tel']) . "', company_bank_account_name = '" . $this->db->escape($data['company_bank_account_name']) . "', company_bank_account_num = '" . $this->db->escape($data['company_bank_account_num']) . "', bank = '" . $this->db->escape($data['bank']) . "', wechat_login_name = '" . $this->db->escape($data['wechat_login_name']) . "', wechat_login_password = '" . $this->db->escape($data['wechat_login_password']) . "', no_1 = '" . $this->db->escape($no_1_childs) . "', no_2 = '" . $this->db->escape($no_2_childs) . "', no_3 = '" . $this->db->escape($no_3_childs) . "', no_4 = '" . $this->db->escape($no_4_childs) . "', status = '" . $this->db->escape($data['status']) . "'");

		$wechat_id = $this->db->getLastId();
		// var_dump($project_progress_id);exit;
		$this->event->trigger('post.admin.WechatInland.add', $wechat_id);
=======
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
		if(isset($data['no_5_child'])){
			$no_5_childs = implode(",",$data['no_5_child']);
		}
		if(isset($data['no_6_child'])){
			$no_6_childs = implode(",",$data['no_6_child']);
		}
		if(isset($data['no_7_child'])){
			$no_7_childs = implode(",",$data['no_7_child']);
		}
		if(isset($data['no_8_child'])){
			$no_8_childs = implode(",",$data['no_8_child']);
		}
		if(isset($data['no_9_child'])){
			$no_9_childs = implode(",",$data['no_9_child']);
		}
		if(isset($data['no_10_child'])){
			$no_10_childs = implode(",",$data['no_10_child']);
		}
		if(isset($data['no_11_child'])){
			$no_11_childs = implode(",",$data['no_11_child']);
		}
		if(isset($data['no_12_child'])){
			$no_12_childs = implode(",",$data['no_12_child']);
		}
		if(isset($data['no_13_child'])){
			$no_13_childs = implode(",",$data['no_13_child']);
		}
		// if(isset($data['no_14_child'])){
		// 	$no_14_childs = implode(",",$data['no_14_child']);
		// }
		// if(isset($data['no_15_child'])){
		// 	$no_15_childs = implode(",",$data['no_15_child']);
		// }
		if(isset($data['no_16_child'])){
			$no_16_childs = implode(",",$data['no_16_child']);
		}
		if(isset($data['no_17_child'])){
			$no_17_childs = implode(",",$data['no_17_child']);
		}
		// var_dump($no_1_childs);exit;

		$this->db->query("INSERT INTO " . DB_PREFIX . "project_progress SET ckg_number = '" . $this->db->escape($data['ckg_number']) . "', project_name = '" . $this->db->escape($data['project_name']) . "', project_customer_id = '" . $this->db->escape($data['project_customer_id']) . "', vendor_details_id_1 = '" . $this->db->escape($data['vendor_1_id']) . "', vendor_details_id_2 = '" . $this->db->escape($data['vendor_2_id']) . "', vendor_details_id_3 = '" . $this->db->escape($data['vendor_3_id']) . "', no_1 = '" . $this->db->escape($no_1_childs) . "', no_2 = '" . $this->db->escape(strtotime($data['no_2'])) . "', no_3 = '" . $this->db->escape($data['no_3']) . "', no_4 = '" . $this->db->escape($data['no_4']) . "', no_5 = '" . $this->db->escape($no_5_childs) . "', no_6 = '" . $this->db->escape($no_6_childs) . "', no_7 = '" . $this->db->escape($no_7_childs) . "', no_8 = '" . $this->db->escape($no_8_childs) . "', no_9 = '" . $this->db->escape($no_9_childs) . "', no_10 = '" . $this->db->escape($no_10_childs) . "', no_11 = '" . $this->db->escape($no_11_childs) . "', no_12 = '" . $this->db->escape($no_12_childs) . "', no_13 = '" . $this->db->escape($no_13_childs) .  "', no_16 = '" . $this->db->escape($no_16_childs) . "', no_17 = '" . $this->db->escape($no_17_childs) . "', confirm = '" . $this->db->escape($data['confirm']) . "', follow_up_history = '" . $this->db->escape($data['follow_up_history']) . "', status = '" . $this->db->escape($data['status']) . "', remark = '" . $this->db->escape($data['remark']) . "', submission_date = '" . $this->db->escape(strtotime($data['submission_date'])) . "', approval_date = '" . $this->db->escape(strtotime($data['approval_date'])) . "', agreement_date = '" . $this->db->escape(strtotime($data['agreement_date'])) . "', date_for_submission_of_grant = '" . $this->db->escape(strtotime($data['date_for_submission_of_grant'])) . "', grant_date = '" . $this->db->escape(strtotime($data['grant_date'])) . "', user_id = '" . $this->user->getId() . "', vendor_quote_1 = '" . $this->db->escape(str_replace(',','',$data['vendor_quote_1'])) . "', vendor_quote_2 = '" . $this->db->escape(str_replace(',','',$data['vendor_quote_2'])) . "', vendor_quote_3 = '" . $this->db->escape(str_replace(',','',$data['vendor_quote_3'])) . "'");

		$project_progress_id = $this->db->getLastId();
		// var_dump($project_progress_id);exit;
		$this->event->trigger('post.admin.vendor_details.add', $project_progress_id);
<<<<<<< HEAD
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa

		return $vendor_details_id;
	}

<<<<<<< HEAD
<<<<<<< HEAD
	public function editWechatInland($wechat_id, $data) {

		// var_dump($data);exit;
		$this->event->trigger('pre.admin.WechatInland.edit', $data);
		if(isset($data['no_1_child'])){
			$no_1_childs = implode(",",$data['no_1_child']);
		}
		if(isset($data['no_2_child'])){
			$no_2_childs = implode(",",$data['no_2_child']);
		}
		if(isset($data['no_3_child'])){
			$no_3_childs = implode(",",$data['no_3_child']);
		}
		if(isset($data['no_4_child'])){
			$no_4_childs = implode(",",$data['no_4_child']);
		}
		$this->db->query("UPDATE " . DB_PREFIX . "company_wechat_inland SET customer_name = '" . $this->db->escape($data['customer_name']) . "', admin_name = '" . $this->db->escape($data['admin_name']) . "', admin_email = '" . $this->db->escape($data['admin_email']) . "', admin_tel = '" . $this->db->escape($data['admin_tel']) . "', company_tel = '" . $this->db->escape($data['company_tel']) . "', company_bank_account_name = '" . $this->db->escape($data['company_bank_account_name']) . "', company_bank_account_num = '" . $this->db->escape($data['company_bank_account_num']) . "', bank = '" . $this->db->escape($data['bank']) . "', wechat_login_name = '" . $this->db->escape($data['wechat_login_name']) . "', wechat_login_password = '" . $this->db->escape($data['wechat_login_password']) . "', no_1 = '" . $this->db->escape($no_1_childs) . "', no_2 = '" . $this->db->escape($no_2_childs) . "', no_3 = '" . $this->db->escape($no_3_childs) . "', no_4 = '" . $this->db->escape($no_4_childs) . "', status = '" . $this->db->escape($data['status']) . "' WHERE wechat_id = '" . (int)$wechat_id . "'");
		
		$this->event->trigger('post.admin.WechatInland.edit', $wechat_id);
	}

=======
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
	public function editVendorChecklist($project_progress_id, $data) {

		// var_dump($data);exit;
		$this->event->trigger('pre.admin.vendor.edit', $data);
		if(isset($data['no_1_child'])){
			$no_1_childs = implode(",",$data['no_1_child']);
		}
		if(isset($data['no_5_child'])){
			$no_5_childs = implode(",",$data['no_5_child']);
		}
		if(isset($data['no_6_child'])){
			$no_6_childs = implode(",",$data['no_6_child']);
		}
		if(isset($data['no_7_child'])){
			$no_7_childs = implode(",",$data['no_7_child']);
		}
		if(isset($data['no_8_child'])){
			$no_8_childs = implode(",",$data['no_8_child']);
		}
		if(isset($data['no_9_child'])){
			$no_9_childs = implode(",",$data['no_9_child']);
		}
		if(isset($data['no_10_child'])){
			$no_10_childs = implode(",",$data['no_10_child']);
		}
		if(isset($data['no_11_child'])){
			$no_11_childs = implode(",",$data['no_11_child']);
		}
		if(isset($data['no_12_child'])){
			$no_12_childs = implode(",",$data['no_12_child']);
		}
		if(isset($data['no_13_child'])){
			$no_13_childs = implode(",",$data['no_13_child']);
		}
		// if(isset($data['no_14_child'])){
		// 	$no_14_childs = implode(",",$data['no_14_child']);
		// }
		// if(isset($data['no_15_child'])){
		// 	$no_15_childs = implode(",",$data['no_15_child']);
		// }
		if(isset($data['no_16_child'])){
			$no_16_childs = implode(",",$data['no_16_child']);
		}
		if(isset($data['no_17_child'])){
			$no_17_childs = implode(",",$data['no_17_child']);
		}
		// var_dump($data);exit;
		$follow_up_history = $query->row['follow_up_history'];
		$this->db->query("UPDATE " . DB_PREFIX . "project_progress SET ckg_number = '" . $this->db->escape($data['ckg_number']) . "', project_name = '" . $this->db->escape($data['project_name']) . "', project_customer_id = '" . $this->db->escape($data['project_customer_id']) . "', vendor_details_id_1 = '" . $this->db->escape($data['vendor_1_id']) . "', vendor_details_id_2 = '" . $this->db->escape($data['vendor_2_id']) . "', vendor_details_id_3 = '" . $this->db->escape($data['vendor_3_id']) . "', no_1 = '" . $this->db->escape($no_1_childs) . "', no_2 = '" . $this->db->escape(strtotime($data['no_2'])) . "', no_3 = '" . $this->db->escape($data['no_3']) . "', no_4 = '" . $this->db->escape($data['no_4']) . "', no_5 = '" . $this->db->escape($no_5_childs) . "', no_6 = '" . $this->db->escape($no_6_childs) . "', no_7 = '" . $this->db->escape($no_7_childs) . "', no_8 = '" . $this->db->escape($no_8_childs) . "', no_9 = '" . $this->db->escape($no_9_childs) . "', no_10 = '" . $this->db->escape($no_10_childs) . "', no_11 = '" . $this->db->escape($no_11_childs) . "', no_12 = '" . $this->db->escape($no_12_childs) . "', no_13 = '" . $this->db->escape($no_13_childs) .  "', no_16 = '" . $this->db->escape($no_16_childs) . "', no_17 = '" . $this->db->escape($no_17_childs) . "', confirm = '" . $this->db->escape($data['confirm']) . "', follow_up_history = '" . $this->db->escape($data['follow_up_history']) . "', status = '" . $this->db->escape($data['status']) . "', remark = '" . $this->db->escape($data['remark']) . "', submission_date = '" . $this->db->escape(strtotime($data['submission_date'])) . "', approval_date = '" . $this->db->escape(strtotime($data['approval_date'])) . "', agreement_date = '" . $this->db->escape(strtotime($data['agreement_date'])) . "', date_for_submission_of_grant = '" . $this->db->escape(strtotime($data['date_for_submission_of_grant'])) . "', grant_date = '" . $this->db->escape(strtotime($data['grant_date'])) . "', vendor_quote_1 = '" . $this->db->escape(str_replace(',','',$data['vendor_quote_1'])) . "', vendor_quote_2 = '" . $this->db->escape(str_replace(',','',$data['vendor_quote_2'])) . "', vendor_quote_3 = '" . $this->db->escape(str_replace(',','',$data['vendor_quote_3'])) . "' WHERE project_progress_id = '" . (int)$project_progress_id . "'");
		
		$this->event->trigger('post.admin.vendor.edit', $project_progress_id);
	}

	public function deleteVendorChecklist($project_progress_id) {
		$this->event->trigger('pre.admin.vendor.delete', $project_progress_id);

		$query = $this->db->query("SELECT no_1,no_5,no_6,no_7,no_8,no_9,no_10,no_11,no_12,no_13,no_14,no_15,no_16,no_17,confirm FROM " . DB_PREFIX . "project_progress WHERE project_progress_id = '" . (int)$project_progress_id . "'");
		if(!empty($query->row['no_1'])){
			$file = $this->db->query("SELECT file_url FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . (int)$query->row['no_1'] . ")");
			foreach ($file->rows as $key => $value) {
				if (is_file($value['file_url'])) {
					unlink($value['file_url']);
				} elseif (is_dir($value['file_url'])) {
					rmdir($value['file_url']);
				}
			}

		}

		if(!empty($query->row['no_5'])){
			$file = $this->db->query("SELECT file_url FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . (int)$query->row['no_5'] . ")");
			foreach ($file->rows as $key => $value) {
				// var_dump($value['file_url'],is_dir($value['file_url']));exit;
				if (is_file($value['file_url'])) {
					unlink($value['file_url']);
				} elseif (is_dir($value['file_url'])) {
					rmdir($value['file_url']);
				}
			}

		}
		// exit;
		if(!empty($query->row['no_6'])){
			$file = $this->db->query("SELECT file_url FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . (int)$query->row['no_6'] . ")");
			foreach ($file->rows as $key => $value) {
				if (is_file($value['file_url'])) {
					unlink($value['file_url']);
				} elseif (is_dir($value['file_url'])) {
					rmdir($value['file_url']);
				}
			}

		}

		if(!empty($query->row['no_7'])){
			$file = $this->db->query("SELECT file_url FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . (int)$query->row['no_7'] . ")");
			foreach ($file->rows as $key => $value) {
				if (is_file($value['file_url'])) {
					unlink($value['file_url']);
				} elseif (is_dir($value['file_url'])) {
					rmdir($value['file_url']);
				}
			}

		}

		if(!empty($query->row['no_8'])){
			$file = $this->db->query("SELECT file_url FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . (int)$query->row['no_8'] . ")");
			foreach ($file->rows as $key => $value) {
				if (is_file($value['file_url'])) {
					unlink($value['file_url']);
				} elseif (is_dir($value['file_url'])) {
					rmdir($value['file_url']);
				}
			}

		}

		if(!empty($query->row['no_9'])){
			$file = $this->db->query("SELECT file_url FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . (int)$query->row['no_9'] . ")");
			foreach ($file->rows as $key => $value) {
				if (is_file($value['file_url'])) {
					unlink($value['file_url']);
				} elseif (is_dir($value['file_url'])) {
					rmdir($value['file_url']);
				}
			}

		}

		if(!empty($query->row['no_10'])){
			$file = $this->db->query("SELECT file_url FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . (int)$query->row['no_10'] . ")");
			foreach ($file->rows as $key => $value) {
				if (is_file($value['file_url'])) {
					unlink($value['file_url']);
				} elseif (is_dir($value['file_url'])) {
					rmdir($value['file_url']);
				}
			}

		}

		if(!empty($query->row['no_11'])){
			$file = $this->db->query("SELECT file_url FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . (int)$query->row['no_11'] . ")");
			foreach ($file->rows as $key => $value) {
				if (is_file($value['file_url'])) {
					unlink($value['file_url']);
				} elseif (is_dir($value['file_url'])) {
					rmdir($value['file_url']);
				}
			}

		}

		if(!empty($query->row['no_12'])){
			$file = $this->db->query("SELECT file_url FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . (int)$query->row['no_12'] . ")");
			foreach ($file->rows as $key => $value) {
				if (is_file($value['file_url'])) {
					unlink($value['file_url']);
				} elseif (is_dir($value['file_url'])) {
					rmdir($value['file_url']);
				}
			}

		}

		if(!empty($query->row['no_13'])){
			$file = $this->db->query("SELECT file_url FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . (int)$query->row['no_13'] . ")");
			foreach ($file->rows as $key => $value) {
				if (is_file($value['file_url'])) {
					unlink($value['file_url']);
				} elseif (is_dir($value['file_url'])) {
					rmdir($value['file_url']);
				}
			}

		}

		if(!empty($query->row['no_14'])){
			$file = $this->db->query("SELECT file_url FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . (int)$query->row['no_14'] . ")");
			foreach ($file->rows as $key => $value) {
				if (is_file($value['file_url'])) {
					unlink($value['file_url']);
				} elseif (is_dir($value['file_url'])) {
					rmdir($value['file_url']);
				}
			}

		}

		if(!empty($query->row['no_15'])){
			$file = $this->db->query("SELECT file_url FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . (int)$query->row['no_15'] . ")");
			foreach ($file->rows as $key => $value) {
				if (is_file($value['file_url'])) {
					unlink($value['file_url']);
				} elseif (is_dir($value['file_url'])) {
					rmdir($value['file_url']);
				}
			}

		}

		if(!empty($query->row['no_16'])){
			$file = $this->db->query("SELECT file_url FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . (int)$query->row['no_16'] . ")");
			foreach ($file->rows as $key => $value) {
				if (is_file($value['file_url'])) {
					unlink($value['file_url']);
				} elseif (is_dir($value['file_url'])) {
					rmdir($value['file_url']);
				}
			}

		}

		if(!empty($query->row['no_17'])){
			$file = $this->db->query("SELECT file_url FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . (int)$query->row['no_17'] . ")");
			foreach ($file->rows as $key => $value) {
				if (is_file($value['file_url'])) {
					unlink($value['file_url']);
				} elseif (is_dir($value['file_url'])) {
					rmdir($value['file_url']);
				}
			}

		}
		
		if(!empty($query->row['confirm'])){
			$file = $this->db->query("SELECT file_url FROM " . DB_PREFIX . "project_file WHERE project_file_id = '" . (int)$query->row['confirm'] . "'");
			if (is_file($file->row['file_url'])) {
				unlink($file->row['file_url']);
			} elseif (is_dir($file->row['file_url'])) {
				rmdir($file->row['file_url']);
			}
		}

		$no_1 = (!empty($query->row['no_1']))?$query->row['no_1']:0;
		$no_5 = (!empty($query->row['no_5']))?$query->row['no_5']:0;
		$no_6 = (!empty($query->row['no_6']))?$query->row['no_6']:0;
		$no_7 = (!empty($query->row['no_7']))?$query->row['no_7']:0;
		$no_8 = (!empty($query->row['no_8']))?$query->row['no_8']:0;
		$no_9 = (!empty($query->row['no_9']))?$query->row['no_9']:0;
		$no_10 = (!empty($query->row['no_10']))?$query->row['no_10']:0;
		$no_11 = (!empty($query->row['no_11']))?$query->row['no_11']:0;
		$no_12 = (!empty($query->row['no_12']))?$query->row['no_12']:0;
		$no_13 = (!empty($query->row['no_13']))?$query->row['no_13']:0;
		$no_14 = (!empty($query->row['no_14']))?$query->row['no_14']:0;
		$no_15 = (!empty($query->row['no_15']))?$query->row['no_15']:0;
		$no_16 = (!empty($query->row['no_16']))?$query->row['no_16']:0;
		$no_17 = (!empty($query->row['no_17']))?$query->row['no_17']:0;

		$this->db->query("DELETE FROM `" . DB_PREFIX . "project_file` WHERE project_file_id in (" . $no_1.",".$no_5.",".$no_6.",".$no_7.",".$no_8.",".$no_9.",".$no_10.",".$no_11.",".$no_12.",".$no_13.",".$no_14.",".$no_15.",".$no_16.",".$no_17.",".(int)$query->row['confirm']. ")");
		$this->db->query("DELETE FROM `" . DB_PREFIX . "project_progress` WHERE project_progress_id = '" . (int)$project_progress_id . "'");

		$this->event->trigger('post.admin.vendor.delete', $project_progress_id);
	}
<<<<<<< HEAD
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa

	public function repairCategories($parent_id = 0) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category WHERE parent_id = '" . (int)$parent_id . "'");

		foreach ($query->rows as $category) {
			// Delete the path below the current one
			$this->db->query("DELETE FROM `" . DB_PREFIX . "category_path` WHERE category_id = '" . (int)$category['category_id'] . "'");

			// Fix for records with no paths
			$level = 0;

			$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category_path` WHERE category_id = '" . (int)$parent_id . "' ORDER BY level ASC");

			foreach ($query->rows as $result) {
				$this->db->query("INSERT INTO `" . DB_PREFIX . "category_path` SET category_id = '" . (int)$category['category_id'] . "', `path_id` = '" . (int)$result['path_id'] . "', level = '" . (int)$level . "'");

				$level++;
			}

			$this->db->query("REPLACE INTO `" . DB_PREFIX . "category_path` SET category_id = '" . (int)$category['category_id'] . "', `path_id` = '" . (int)$category['category_id'] . "', level = '" . (int)$level . "'");

			$this->repairCategories($category['category_id']);
		}
	}

<<<<<<< HEAD
<<<<<<< HEAD
	public function getWecahtInland($wechat_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "company_wechat_inland WHERE wechat_id = '" . (int)$wechat_id . "'");
			if(!empty($query->row['no_1'])){
			$query1 = $this->db->query("SELECT * FROM " . DB_PREFIX . "company_wechat_file WHERE wechat_file_id in (" . $query->row['no_1'] . ")");
			}
			if(!empty($query->row['no_2'])){
			$query2 = $this->db->query("SELECT * FROM " . DB_PREFIX . "company_wechat_file WHERE wechat_file_id in (" . $query->row['no_2'] . ")");
			}
			if(!empty($query->row['no_3'])){
			$query3 = $this->db->query("SELECT * FROM " . DB_PREFIX . "company_wechat_file WHERE wechat_file_id in (" . $query->row['no_3'] . ")");
			}
			if(!empty($query->row['no_4'])){
			$query4 = $this->db->query("SELECT * FROM " . DB_PREFIX . "company_wechat_file WHERE wechat_file_id in (" . $query->row['no_4'] . ")");
			}

			$query->row['data'] = array(
				'no_1' => (!empty($query1->rows))?$query1->rows:'',
				'no_2' => (!empty($query2->rows))?$query2->rows:'',
				'no_3' => (!empty($query3->rows))?$query3->rows:'',
				'no_4' => (!empty($query4->rows))?$query4->rows:'',
=======
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
	public function getVendors($project_progress_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_progress WHERE project_progress_id = '" . (int)$project_progress_id . "'");
			if(!empty($query->row['no_1'])){
			$query1 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . $query->row['no_1'] . ")");
			}
			if(!empty($query->row['no_5'])){
			$query5 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . $query->row['no_5'] . ")");
			}
			if(!empty($query->row['no_6'])){
			$query6 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . $query->row['no_6'] . ")");
			}
			if(!empty($query->row['no_7'])){
			$query7 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . $query->row['no_7'] . ")");
			}
			if(!empty($query->row['no_8'])){
			$query8 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . $query->row['no_8'] . ")");
			}
			if(!empty($query->row['no_9'])){
			$query9 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . $query->row['no_9'] . ")");
			}
			if(!empty($query->row['no_10'])){
			$query10 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . $query->row['no_10'] . ")");
			}
			if(!empty($query->row['no_11'])){
			$query11 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . $query->row['no_11'] . ")");
			}
			if(!empty($query->row['no_12'])){
			$query12 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . $query->row['no_12'] . ")");
			}
			if(!empty($query->row['no_13'])){
			$query13 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . $query->row['no_13'] . ")");
			}
			// if(!empty($query->row['no_14'])){
			// $query14 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . $query->row['no_14'] . ")");
			// }
			// if(!empty($query->row['no_15'])){
			// $query15 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . $query->row['no_15'] . ")");
			// }
			if(!empty($query->row['no_16'])){
			$query16 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . $query->row['no_16'] . ")");
			}
			if(!empty($query->row['no_17'])){
			$query17 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id in (" . $query->row['no_17'] . ")");
			}



			$queryvendor1 = $this->db->query("SELECT english_name_of_supplier FROM " . DB_PREFIX . "vendor_details WHERE vendor_details_id = '" . (int)$query->row['vendor_details_id_1'] . "'");
			$queryvendor2 = $this->db->query("SELECT english_name_of_supplier FROM " . DB_PREFIX . "vendor_details WHERE vendor_details_id = '" . (int)$query->row['vendor_details_id_2'] . "'");
			$queryvendor3 = $this->db->query("SELECT english_name_of_supplier FROM " . DB_PREFIX . "vendor_details WHERE vendor_details_id = '" . (int)$query->row['vendor_details_id_3'] . "'");

			$queryname = $this->db->query("SELECT company_eng_name FROM " . DB_PREFIX . "project_customer WHERE project_customer_id = '" . (int)$query->row['project_customer_id'] . "'");
			$query->row['data'] = array(
				'no_1' => (!empty($query1->rows))?$query1->rows:'',
				'no_5' => (!empty($query5->rows))?$query5->rows:'',
				'no_6' => (!empty($query6->rows))?$query6->rows:'',
				'no_7' => (!empty($query7->rows))?$query7->rows:'',
				'no_8' => (!empty($query8->rows))?$query8->rows:'',
				'no_9' => (!empty($query9->rows))?$query9->rows:'',
				'no_10' => (!empty($query10->rows))?$query10->rows:'',
				'no_11' => (!empty($query11->rows))?$query11->rows:'',
				'no_12' => (!empty($query12->rows))?$query12->rows:'',
  				'no_13' => (!empty($query13->rows))?$query13->rows:'',
				'no_16' => (!empty($query16->rows))?$query16->rows:'',
				'no_17' => (!empty($query17->rows))?$query17->rows:'',
				'vendor_1' => (!empty($queryvendor1->row['english_name_of_supplier']))?$queryvendor1->row['english_name_of_supplier']:'',
				'vendor_2' => (!empty($queryvendor2->row['english_name_of_supplier']))?$queryvendor2->row['english_name_of_supplier']:'',
				'vendor_3' => (!empty($queryvendor3->row['english_name_of_supplier']))?$queryvendor3->row['english_name_of_supplier']:'',
				'project_customer' => (!empty($queryname->row['company_eng_name']))?$queryname->row['company_eng_name']:'',

<<<<<<< HEAD
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
			);
		// var_dump($query->row);exit;
		return $query->row;
	}

<<<<<<< HEAD
<<<<<<< HEAD
	public function getWechatList($data = array()) {

		// $sql = "SELECT pp.*,pc.company_eng_name,pc.company_chn_name,pc.contact_person_eng_name,pc.contact_person_chn_name,pc.contact_person_tel,pc.contact_person_email,ps.sort,vd.english_name_of_supplier,vd.vendor_details_id FROM " . DB_PREFIX . "project_progress pp LEFT JOIN " . DB_PREFIX . "project_customer pc ON (pp.project_customer_id = pc.project_customer_id) LEFT JOIN " . DB_PREFIX . "project_status ps ON (pp.status = ps.project_status_id) LEFT JOIN " . DB_PREFIX ."vendor_details vd ON (pp.vendor_details_id_1 = vd.vendor_details_id) WHERE 1=1 ";

		$sql = "SELECT * FROM " . DB_PREFIX . "company_wechat_inland WHERE 1=1 ";

		if (!empty($data['filter_customer_name'])) {
			$sql .= " AND customer_name LIKE '" . $this->db->escape($data['filter_customer_name']) . "%'";
		}

		if (!empty($data['filter_admin_name'])) {
			$sql .= " AND admin_name LIKE '" . $this->db->escape($data['filter_admin_name']) . "%'";
		}

		if (!empty($data['filter_admin_tel'])) {
			$sql .= " AND admin_tel LIKE '" . $this->db->escape($data['filter_admin_tel']) . "%'";
		}

		if (!empty($data['filter_bank'])) {
			$sql .= " AND bank LIKE '" . $this->db->escape($data['filter_bank']) . "%'";
		}
		// if (!empty($data['filter_customer_name']) && !empty($data['filter_customer_value']) ) {
		// 	$sql .= " AND " . $this->db->escape($data['filter_customer_name']) . " LIKE '%" . $this->db->escape($data['filter_customer_value']) . "%'";
		// }

		if (isset($data['filter_status']) && !is_null($data['filter_status'])) {
			$sql .= " AND status = '" . (int)$data['filter_status'] . "'";
		}

		$sql .= " GROUP BY wechat_id ";

		$sort_data = array(
			'customer_name',
			'admin_name',
			'admin_tel',
		);
		if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
			$sql .= " ORDER BY sort," . $data['sort'];
		} else {
			$sql .= " ORDER BY wechat_id";
=======
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
	public function getProjectProgresslist($data = array()) {
		// var_dump($data);exit;
		// getGroupId
		// var_dump($this->user->getId());exit;
		$sql = "SELECT pp.*,pc.company_eng_name,pc.company_chn_name,pc.contact_person_eng_name,pc.contact_person_chn_name,pc.contact_person_tel,pc.contact_person_email,ps.sort,vd.english_name_of_supplier,vd.vendor_details_id FROM " . DB_PREFIX . "project_progress pp LEFT JOIN " . DB_PREFIX . "project_customer pc ON (pp.project_customer_id = pc.project_customer_id) LEFT JOIN " . DB_PREFIX . "project_status ps ON (pp.status = ps.project_status_id) LEFT JOIN " . DB_PREFIX ."vendor_details vd ON (pp.vendor_details_id_1 = vd.vendor_details_id) WHERE 1=1 ";

		// $sql = "SELECT * FROM " . DB_PREFIX . "project_progress WHERE 1=1 ";

		if($this->user->getGroupId() != 1 ){
			$sql .= " AND pp.user_id = '" . $this->user->getId() . "'";
		}
		if (!empty($data['filter_ckg_number'])) {
			$sql .= " AND pp.ckg_number LIKE '" . $this->db->escape($data['filter_ckg_number']) . "%'";
		}

		if (!empty($data['filter_project_name'])) {
			$sql .= " AND pp.project_name LIKE '" . $this->db->escape($data['filter_project_name']) . "%'";
		}

		if (!empty($data['filter_english_name_of_supplier'])) {
			$sql .= " AND vd.english_name_of_supplier LIKE '" . $this->db->escape($data['filter_english_name_of_supplier']) . "%'";
		}

		if (!empty($data['filter_customer_name']) && !empty($data['filter_customer_value']) ) {
			$sql .= " AND pc." . $this->db->escape($data['filter_customer_name']) . " LIKE '%" . $this->db->escape($data['filter_customer_value']) . "%'";
		}

		if (isset($data['filter_status']) && !is_null($data['filter_status'])) {
			if($data['filter_status'] != 'all'){
				$sql .= " AND pp.status = '" . (int)$data['filter_status'] . "'"; 
			}
		}else{
			$sql .= " AND ps.sort in (1,2,5) "; 
		}

		$sql .= " GROUP BY pp.project_progress_id ";

		$sort_data = array(
			'pp.ckg_number',
			'pp.project_name',
			'pp.project_customer', 
			'pc.'.$this->db->escape($data['filter_customer_name']),
			'pp.status',
			'pp.sort_order'
		);

		if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
			$sql .= " ORDER BY ps.sort," . $data['sort'];
		} else {
			$sql .= " ORDER BY ps.sort,pp.project_progress_id";
<<<<<<< HEAD
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
		}

		if (isset($data['order']) && ($data['order'] == 'DESC')) {
			$sql .= " DESC";
		} else if(isset($data['order']) && ($data['order'] == 'ASC')){
			$sql .= " ASC";
		} else {
			$sql .= " DESC";
		}

		if (isset($data['start']) || isset($data['limit'])) {
			if ($data['start'] < 0) {
				$data['start'] = 0;
			}

			if ($data['limit'] < 1) {
				$data['limit'] = 20;
			}

			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
		}
<<<<<<< HEAD
<<<<<<< HEAD

		$query = $this->db->query($sql);


=======
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
		// var_dump($sql,$data['order']);exit;
		$query = $this->db->query($sql);
		// var_dump($query->rows);exit;
				foreach ($query->rows as $key => &$value) {

			$query1 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id = '" . (int)$value['no_1'] . "'");
			$query5 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id = '" . (int)$value['no_5'] . "'");
			$query6 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id = '" . (int)$value['no_6'] . "'");
			$query7 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id = '" . (int)$value['no_7'] . "'");
			$query8 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id = '" . (int)$value['no_8'] . "'");
			$query9 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id = '" . (int)$value['no_9'] . "'");
			$query10 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id = '" . (int)$value['no_10'] . "'");
			$query11 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id = '" . (int)$value['no_11'] . "'");
			$query12 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id = '" . (int)$value['no_12'] . "'");
			$query13 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id = '" . (int)$value['no_13'] . "'");
			
			$query15 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id = '" . (int)$value['no_15'] . "'");
			$query16 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id = '" . (int)$value['no_16'] . "'");
			$query17 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id = '" . (int)$value['no_17'] . "'");

			$queryStatus = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_status WHERE project_status_id = '" . (int)$value['status'] . "'");

			$queryvendor1 = $this->db->query("SELECT english_name_of_supplier,vendor_br_id FROM " . DB_PREFIX . "vendor_details WHERE vendor_details_id = '" . (int)$value['vendor_details_id_1'] . "'");
			$queryvendor2 = $this->db->query("SELECT english_name_of_supplier FROM " . DB_PREFIX . "vendor_details WHERE vendor_details_id = '" . (int)$value['vendor_details_id_2'] . "'");
			$queryvendor3 = $this->db->query("SELECT english_name_of_supplier FROM " . DB_PREFIX . "vendor_details WHERE vendor_details_id = '" . (int)$value['vendor_details_id_3'] . "'");

			$vendor_1_project_file_id = (!empty($queryvendor1->row['vendor_br_id']))?$queryvendor1->row['vendor_br_id']:0;
			$query14 = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id = '" . (int)$vendor_1_project_file_id . "'");


			$queryname = $this->db->query("SELECT company_eng_name FROM " . DB_PREFIX . "project_customer WHERE project_customer_id = '" . (int)$value['project_customer_id'] . "'");
			$query->rows[$key]['data'] = array(
				'no_1' => (!empty($query1->row))?$query1->row:'',
				'no_5' => (!empty($query5->row))?$query5->row:'',
				'no_6' => (!empty($query6->row))?$query6->row:'',
				'no_7' => (!empty($query7->row))?$query7->row:'',
				'no_8' => (!empty($query8->row))?$query8->row:'',
				'no_9' => (!empty($query9->row))?$query9->row:'',
				'no_10' => (!empty($query10->row))?$query10->row:'',
				'no_11' => (!empty($query11->row))?$query11->row:'',
				'no_12' => (!empty($query12->row))?$query12->row:'',
				'no_13' => (!empty($query13->row))?$query13->row:'',
				'no_14' => (!empty($query14->row))?$query14->row:'',
				'no_16' => (!empty($query16->row))?$query16->row:'',
				'no_17' => (!empty($query17->row))?$query17->row:'',
				'vendor_1' => (!empty($queryvendor1->row['english_name_of_supplier']))?$queryvendor1->row['english_name_of_supplier']:'',
				'vendor_2' => (!empty($queryvendor2->row['english_name_of_supplier']))?$queryvendor2->row['english_name_of_supplier']:'',
				'vendor_3' => (!empty($queryvendor3->row['english_name_of_supplier']))?$queryvendor3->row['english_name_of_supplier']:'',
				'project_customer' => (!empty($queryname->row['company_eng_name']))?$queryname->row['company_eng_name']:'',
				'status' => (!empty($queryStatus->row))?$queryStatus->row:''

			);
		}
		// var_dump($query->rows);exit;
<<<<<<< HEAD
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
		return $query->rows;
	}
	public function getPojectCustomers($data = array()) {
		$sql = "SELECT * FROM " . DB_PREFIX . "project_customer WHERE 1=1 AND customer_status = 1 ";

		if (!empty($data['filter_name'])) {
			$sql .= " AND company_eng_name LIKE '" . $this->db->escape($data['filter_name']) . "%'";
		}

		if (isset($data['start']) || isset($data['limit'])) {
			if ($data['start'] < 0) {
				$data['start'] = 0;
			}

			if ($data['limit'] < 1) {
				$data['limit'] = 20;
			}

			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
		}

		$query = $this->db->query($sql);

		// var_dump($query->rows);exit;
		return $query->rows;
	}

<<<<<<< HEAD
<<<<<<< HEAD

	public function getTotalCategories($data = array()) {
		$sql = "SELECT COUNT(DISTINCT wechat_id) AS total FROM " . DB_PREFIX . "company_wechat_inland WHERE 1=1 ";

		if (!empty($data['filter_customer_name'])) {
			$sql .= " AND customer_name LIKE '" . $this->db->escape($data['filter_customer_name']) . "%'";
		}

		if (!empty($data['filter_admin_name'])) {
			$sql .= " AND admin_name LIKE '" . $this->db->escape($data['filter_admin_name']) . "%'";
		}

		if (!empty($data['filter_admin_tel'])) {
			$sql .= " AND admin_tel LIKE '" . $this->db->escape($data['filter_admin_tel']) . "%'";
		}

		if (!empty($data['filter_bank'])) {
			$sql .= " AND bank LIKE '" . $this->db->escape($data['filter_bank']) . "%'";
		}
		// if (!empty($data['filter_customer_name']) && !empty($data['filter_customer_value']) ) {
		// 	$sql .= " AND " . $this->db->escape($data['filter_customer_name']) . " LIKE '%" . $this->db->escape($data['filter_customer_value']) . "%'";
		// }

		if (isset($data['filter_status']) && !is_null($data['filter_status'])) {
			$sql .= " AND status = '" . (int)$data['filter_status'] . "'";
=======
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
	public function getPojectVendor($data = array()) {
		$sql = "SELECT * FROM " . DB_PREFIX . "vendor_details WHERE 1=1 AND vendor_status = 1 ";

		if (!empty($data['filter_name'])) {
			$sql .= " AND english_name_of_supplier LIKE '" . $this->db->escape($data['filter_name']) . "%'";
		}

		if (isset($data['start']) || isset($data['limit'])) {
			if ($data['start'] < 0) {
				$data['start'] = 0;
			}

			if ($data['limit'] < 1) {
				$data['limit'] = 20;
			}

			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
		}

		$query = $this->db->query($sql);

		// var_dump($query->rows);exit;
		return $query->rows;
	}

	public function getVendorChecklists($data = array()) {
		$sql = "SELECT * FROM " . DB_PREFIX . "project_progress WHERE 1=1 ";

		if (!empty($data['filter_ckg_number'])) {
			$sql .= " AND ckg_number LIKE '" . $this->db->escape($data['filter_ckg_number']) . "%'";
		}

		if (!empty($data['filter_project_name'])) {
			$sql .= " AND project_name LIKE '" . $this->db->escape($data['filter_project_name']) . "%'";
		}

		if (isset($data['start']) || isset($data['limit'])) {
			if ($data['start'] < 0) {
				$data['start'] = 0;
			}

			if ($data['limit'] < 1) {
				$data['limit'] = 20;
			}

			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
		}

		$query = $this->db->query($sql);

		// var_dump($query->rows);exit;
		return $query->rows;
	}
	public function getCategoryDescriptions($category_id) {
		$category_description_data = array();

		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category_description WHERE category_id = '" . (int)$category_id . "'");

		foreach ($query->rows as $result) {
			$category_description_data[$result['language_id']] = array(
				'name'             => $result['name'],
				'meta_title'       => $result['meta_title'],
				'meta_description' => $result['meta_description'],
				'meta_keyword'     => $result['meta_keyword'],
				'description'      => $result['description']
			);
		}

		return $category_description_data;
	}

	public function getCategoryFilters($category_id) {
		$category_filter_data = array();

		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category_filter WHERE category_id = '" . (int)$category_id . "'");

		foreach ($query->rows as $result) {
			$category_filter_data[] = $result['filter_id'];
		}

		return $category_filter_data;
	}

	public function getCategoryStores($category_id) {
		$category_store_data = array();

		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category_to_store WHERE category_id = '" . (int)$category_id . "'");

		foreach ($query->rows as $result) {
			$category_store_data[] = $result['store_id'];
		}

		return $category_store_data;
	}

	public function getCategoryLayouts($category_id) {
		$category_layout_data = array();

		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category_to_layout WHERE category_id = '" . (int)$category_id . "'");

		foreach ($query->rows as $result) {
			$category_layout_data[$result['store_id']] = $result['layout_id'];
		}

		return $category_layout_data;
	}

	public function getTotalCategories($data = array()) {
		$sql = "SELECT COUNT(DISTINCT pp.project_progress_id) AS total FROM " . DB_PREFIX . "project_progress pp LEFT JOIN " . DB_PREFIX . "project_customer pc ON (pp.project_customer_id = pc.project_customer_id) LEFT JOIN " . DB_PREFIX . "project_status ps ON (pp.status = ps.project_status_id) LEFT JOIN " . DB_PREFIX ."vendor_details vd ON (pp.vendor_details_id_1 = vd.vendor_details_id) WHERE 1=1 ";

		if($this->user->getGroupId() != 1 ){
			$sql .= " AND pp.user_id = '" . $this->user->getId() . "'";
		}
		if (!empty($data['filter_ckg_number'])) {
			$sql .= " AND pp.ckg_number LIKE '" . $this->db->escape($data['filter_ckg_number']) . "%'";
		}

		if (!empty($data['filter_project_name'])) {
			$sql .= " AND pp.project_name LIKE '" . $this->db->escape($data['filter_project_name']) . "%'";
		}

		if (!empty($data['filter_english_name_of_supplier'])) {
			$sql .= " AND vd.english_name_of_supplier LIKE '" . $this->db->escape($data['filter_english_name_of_supplier']) . "%'";
		}

		if (!empty($data['filter_customer_name']) && !empty($data['filter_customer_value']) ) {
			$sql .= " AND pc." . $this->db->escape($data['filter_customer_name']) . " LIKE '%" . $this->db->escape($data['filter_customer_value']) . "%'";
		}

		if (isset($data['filter_status']) && !is_null($data['filter_status'])) {
			$sql .= " AND pp.status = '" . (int)$data['filter_status'] . "'";
<<<<<<< HEAD
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
		}



		$query = $this->db->query($sql);

		return $query->row['total'];
	}
<<<<<<< HEAD
<<<<<<< HEAD


	public function clearFile($wechat_id,$no_name,$name){

		if(isset($wechat_id)){
		$clear = $this->db->query("SELECT `".$no_name."` FROM " . DB_PREFIX . "company_wechat_inland WHERE wechat_id = '" . (int)$wechat_id."'");
		$clearArr = explode(',',$clear->row[$no_name]);
		foreach ($clearArr as $key => $value) {
			if($value == $name){
				unset($clearArr[$key]);
			}
		}
		$clearStr = implode(',',$clearArr);
		$this->db->query("UPDATE " . DB_PREFIX . "company_wechat_inland SET `".$no_name."` = '".$clearStr."'  WHERE wechat_id = '" . (int)$wechat_id."'");
		}
		$query = $this->db->query("SELECT file_url FROM " . DB_PREFIX . "company_wechat_file WHERE wechat_file_id = '" . (int)$name."'");
		$this->db->query("DELETE FROM " . DB_PREFIX . "company_wechat_file WHERE wechat_file_id = '" . (int)$name."'");
=======
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
	
	public function getTotalCategoriesByLayoutId($layout_id) {
		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "category_to_layout WHERE layout_id = '" . (int)$layout_id . "'");

		return $query->row['total'];
	}
	public function checkData($vendor_1,$vendor_2,$vendor_3){
		$query1 = $this->db->query("SELECT director1,director2,director3,director4,director5,shareholder1,shareholder2,shareholder3,shareholder4,shareholder5 FROM " . DB_PREFIX . "vendor_details WHERE vendor_details_id = '" . $vendor_1."'");

		$query2 = $this->db->query("SELECT director1,director2,director3,director4,director5,shareholder1,shareholder2,shareholder3,shareholder4,shareholder5 FROM " . DB_PREFIX . "vendor_details WHERE vendor_details_id = '" . $vendor_2."'");

		$query3 = $this->db->query("SELECT director1,director2,director3,director4,director5,shareholder1,shareholder2,shareholder3,shareholder4,shareholder5 FROM " . DB_PREFIX . "vendor_details WHERE vendor_details_id = '" . $vendor_3."'");

		$q1 = $query1->row;
		$q2 = $query2->row;
		$q3 = $query3->row;
		$result1 = array_filter(array_intersect($q1,$q2));
		$result2 = array_filter(array_intersect($q1,$q3));
		$result3 = array_filter(array_intersect($q2,$q3));
		// var_dump($result1,$result2,$result3);
		if(!empty($result1)){
			return 1;
		}else if(!empty($result2)){
			return 2;
		}else if(!empty($result3)){
			return 3;
		}else{
			return 0;
		}
	}

	public function clearFile($project_progress_id,$no_name,$name){
		// var_dump($project_progress_id,$no_name,$name);exit;
		if(isset($project_progress_id)){
		$this->db->query("UPDATE " . DB_PREFIX . "project_progress SET `".$no_name."` = ''  WHERE project_progress_id = '" . (int)$project_progress_id."'");
		}
		$query = $this->db->query("SELECT file_url FROM " . DB_PREFIX . "project_file WHERE project_file_id = '" . (int)$name."'");
		$this->db->query("DELETE FROM " . DB_PREFIX . "project_file WHERE project_file_id = '" . (int)$name."'");
<<<<<<< HEAD
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
		// var_dump($query->row['file_url']);exit;
		return $query->row['file_url'];
	}


	public function addFile($filename,$uploadfile){
<<<<<<< HEAD
<<<<<<< HEAD
		$this->db->query("INSERT INTO " . DB_PREFIX . "company_wechat_file SET file_name = '" . $this->db->escape($filename) . "', file_url = '" . $this->db->escape($uploadfile) . "'");
			$wechat_id = $this->db->getLastId();
		return $wechat_id;
	}

	public function getFiles($wechat_file_id){
		if(!empty($wechat_file_id)){
			$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "company_wechat_file WHERE wechat_file_id in (".$this->db->escape($wechat_file_id).")");
=======
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
		$this->db->query("INSERT INTO " . DB_PREFIX . "project_file SET file_name = '" . $this->db->escape($filename) . "', file_url = '" . $this->db->escape($uploadfile) . "'");
			$project_file = $this->db->getLastId();
		return $project_file;
	}

	public function getFiles($project_file_id){
		if(!empty($project_file_id)){
			$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id in (".$this->db->escape($project_file_id).")");
<<<<<<< HEAD
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
			return $query->rows;
		}else{
			return false;
		}
	}
<<<<<<< HEAD
<<<<<<< HEAD
	public function getWechatFiles($wechat_file){
		$arr = array();
		foreach ($wechat_file as $key => $value) {
			$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "company_wechat_file WHERE wechat_file_id = '".$this->db->escape($value)."'");
=======
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
	public function getProjectFiles($project_file){
		$arr = array();
		foreach ($project_file as $key => $value) {
			$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file WHERE project_file_id = '".$this->db->escape($value)."'");
<<<<<<< HEAD
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
			$arr[$key] = $query->row;
		}
		// var_dump($arr);exit;
		return $arr;
	}
<<<<<<< HEAD
<<<<<<< HEAD

=======
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
	// public function getStatusall(){
	// 	$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "project_file ORDER BY `sort` DESC");
	// 	return $query->rows;
	// }
<<<<<<< HEAD
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
=======
>>>>>>> d186f0ac043b98de93b00ad49075690d01e0cbaa
	public function getProjectStatus(){
	   $query =	$this->db->query("SELECT * FROM " . DB_PREFIX . "project_status WHERE status = 1 ORDER by sort ASC");
	   return $query->rows;
	}	
}
